<?php
class Mcountuser extends CI_Model{
    public function __construct(){
        parent::__construct();
        $this->load->database();
    }
    public function checkExitsIP($ip){
        $this->db->where('ip_address', $ip);
        $query = $this->db->get('countonline');
            if($query->num_rows >= 1)
            {
                return true;
            }
        return false;
    }
    public function insertIPAccess($ip, $user_agent, $datetime, $time){
        $data = array(
           'ip_address' => $ip,
           'user_agent' => $user_agent,
           'datetime' => $datetime,
           'time' => $time
        );
        $this->db->insert('countonline', $data);
        $last = $this->db->insert_id();
    }

    public function countOnline() {
        return $this->db->count_all('countonline');
    }

    public function deleteIPAccess($time_check){
        $this->db->where('time <', $time_check);
        $this->db->delete('countonline');
    }
}